#!/usr/bin/env python
#

from distutils.core import setup
from distutils.command.install import INSTALL_SCHEMES, DistutilsPlatformError
import os, sys

root_dir = os.path.dirname(__file__)
src_dir = 'src'
pkg_name = 'grdlog'

if os.name == 'posix':
    scheme = INSTALL_SCHEMES['unix_prefix'] # this a deficient assumption
else:
    try:
        scheme = INSTALL_SCHEMES[os.name]
    except KeyError:
        raise DistutilsPlatformError, \
              "I don't know how to install data on '%s'" % os.name

# get string from scheme,
# manually replace distutils internal variables
# (cut $base to make this paths relative)
scheme_prefix = scheme['purelib'
                   ].replace('$base/', ''
                             ).replace('$py_version_short',
                                       sys.version.split(' ', 1)[0][0:3])

if root_dir != '':
    os.chdir(root_dir)

os.chdir(src_dir)
# compile i18n messages
try:
    from django.core import management
    management.call_command('compilemessages')
finally:
    os.chdir('..')

data_files = []
for dirpath, dirnames, filenames in os.walk(src_dir):
    # Ignore dirnames that start with '.'
    for i, dirname in enumerate(dirnames):
        if dirname.startswith('.'): del dirnames[i]
    if not '__init__.py' in filenames:
        data_files.append([os.path.join(scheme_prefix,
                                        dirpath.replace(src_dir, pkg_name)),
                           [os.path.join(dirpath, f) for f in filenames]])

data_files.append(['libexec', ['src/sqlpipe/sqlpipe.tac']])

setup(name = pkg_name,
      version = '0.2.1',
      description = "A tools for aggregating log entries in SQL database",
      author = "Dmitri Bogomolov",
      author_email = '4glitch@gmail.com',
      packages = ['grdlog',
                  'grdlog.templatetags',
                  'grdlog.sqlpipe'],
      package_dir = {'grdlog': 'src'},
      data_files = data_files,
      classifiers = ['Development Status :: 3 - Alpha',
                     'Intended Audience :: System Administrators',
                     'Programming Language :: Python',
                     'Framework :: Twisted',
                     'Topic :: System :: Networking :: Monitoring'],
      )
